﻿/*
 * Created by Ranorex
 * User: taurus
 * Date: 2017/9/17
 * Time: 16:07
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.IO;
using Ranorex;

namespace EpCompareFile_AT.CommonFunction
{
	/// <summary>
	/// Description of CommonFunc.
	/// </summary>
	public class CommonFunc
	{
		public CommonFunc()
		{
		}
		
		#region 返回工程基础路径下目标文件夹的路径
		/// <summary>
		/// 编写日期：2017-9-15
		/// 编写人：袁郑
		/// 功能：返回工程基础路径下目标文件夹的路径
		/// <param name="TarFolder">比较类型</param>
		/// </summary>
		public static string GetBasePath(string TarFolder)
		{
			string basePath = "";
			string returnPath = "";
			
			basePath = System.AppDomain.CurrentDomain.BaseDirectory; //"\EpCompareFile_AT\EpCompareFile_AT\bin\Debug" -- 基准路径
			basePath = basePath.Substring(0,basePath.LastIndexOf("\\"));
			basePath = basePath.Substring(0,basePath.LastIndexOf("\\"));
			basePath = basePath.Substring(0,basePath.LastIndexOf("\\")); 		//"\EpCompareFile_AT\EpCompareFile_AT"
			
			returnPath = basePath + @"\" + TarFolder;
			
			//返回目标文件夹路径
			return returnPath;
		}
		#endregion
		
		#region 判断传入的文件夹路径是否存在，如果不存在就新建文件夹
		/// <summary>
		/// 编写日期：2017-9-17
		/// 编写人：袁郑
		/// 功能：判断传入的文件夹路径是否存在，如果不存在就新建文件夹
		/// <param name="CreateFolderPath">需要创建文件夹的路径</param>
		/// </summary>
		public static void CreateFolder(string CreateFolderPath)
		{
			if (!Directory.Exists(CreateFolderPath))
			{
				Directory.CreateDirectory(CreateFolderPath);
			}
			else
			{
				Report.Info(CreateFolderPath + "已存在，不重复新建");
			}
		}
		#endregion
		
		#region 获取当前日期
		/// <summary>
		/// 编写日期：2017-9-18
		/// 编写人：袁郑
		/// 功能：将当前日期(格式为:2017-09-05 14:35:28) 按照2017-09-05_143528返回。
		/// </summary>
		public static string GetStrCurDateTime()
		{
			System.DateTime dt = System.DateTime.Now; //获取当前时间，格式：2017-09-05 14:35:28;
			string strCurDate = dt.ToString("yyyy'年'M'月'd'日' HH:mm:ss");
			strCurDate = strCurDate.Replace(":","");
			strCurDate = strCurDate.Replace(" ", "_");
			return strCurDate;
		}
		#endregion
		
	}
}
